import collections
class Solution(object):
    def countKDifference(self, nums, k):
        c = collections.Counter(nums)
        ans = 0
        for key in c:
            if key + k in c:
                ans += c[key] * c[key + k]
        return ans